package club.monkeywood.repository;

import club.monkeywood.dataobject.OrderMaster;
import club.monkeywood.dto.buyer.OrderMasterDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


public interface OrderMasterRepository extends JpaRepository<OrderMaster, Integer> {

    @Query(value = "select new club.monkeywood.dto.buyer.OrderMasterDTO(" +
            " a.id, a.buyerId, b.name, b.openid, " +
            " b.avatar, b.email,b.mobilePhone,b.homePhone, " +
            " b.address, a.orderAmount, a.orderStatus, a.payStatus, " +
            " a.createTime, a.updateTime ) " +
            " from OrderMaster a,Buyer b " +
            " where a.buyerId=b.id " +
            " and b.openid=:buyerOpenId")
    Page<OrderMasterDTO> queryByBuyerOpenId(@Param("buyerOpenId") String buyerOpenId, Pageable pageable);

    OrderMaster findById(String orderId);

}
